package day6work;

import day6work.animalclasss.*;

public class testclass {
    public static void main(String[] args) {
        //向上造型
        Animal xg=new Dog(2,"小狗","白色");
        xg.eat();
        Animal xj=new Chick(2,"小鸡","黄色");
        xj.eat();
        Animal xy=new Fish(2,"小鱼","蓝色");
        xy.eat();
        //传参调用
       manger man= new manger();
       man.feed(xg);
       man.feed(xj);


        //向上造型 多态
        Animal[] an=new Animal[3];
        an[0]=new Dog(2,"小狗","白色");
        an[0].eat();
        an[1]=new Chick(2,"小鸡","黄色");
        an[2]=new Fish(2,"小鱼","蓝色");
        for (int i=0;i< an.length;i++){
            System.out.println("第"+i+"只动物的年龄"+an[i].age+"名字"+an[i].name+"颜色"+an[i].color);
            an[i].eat();
            an[i].drink();
            //强转animal类为Dog类的对象
            if(an[i] instanceof Dog){
                Dog dan=(Dog)an[i];
                dan.lookhome();
            }
            //强转animal类为Fish类的对象
            if(an[i] instanceof Fish){
                Fish dan=(Fish) an[i];
                dan.Swim();
            }
            //强转animal类为Chick类的对象
            if(an[i] instanceof Chick){
               Chick dan=(Chick) an[i];
                dan.layeggs();
            }
        }
        //向下造型 多态
//        Animal[] an=new Animal[3];
//        an[0]=new Dog(2,"小狗","白色");
//        an[0].eat();
//        an[1]=new Chick(2,"小鸡","黄色");
//        an[2]=new Fish(2,"小鱼","蓝色");
        Dog dan=(Dog)an[0];
        dan.Swim();
        dan.lookhome();
        Chick can=(Chick)an[1];
        can.layeggs();
        Fish fan=(Fish)an[2];
        fan.Swim();

    }
}
